// 1. 下包 npm i redux react-redux
import {legacy_createStore as createStore} from "redux"
// state 就是放数据的，理解为vuex 得state
// reducer 是一个函数，这个函数内放的内容是一些修改和默认返回state得东西得
// action action 是唯一可以修改state得方法，// 通过dispatch来修改
let initdata = {
    name:"张三",
    age:"20岁",
    sex:"女"
}
// 只有action可以修改state，action需要dispatch来触发
let reducer = (state = initdata,action)=>{
    console.log(state,222222);
    console.log(action,111111);
    if (action.type == "setname") {
        return {
            ...state,
            name:action.payload
        }
    
    } else if (action.type == "setsex"){
        return {
            ...state,
            sex:action.payload
        }
    }
    else {
        return {
            ...state
        }
    }
   
}
let res = createStore(reducer)
console.log(res,11111);
console.log(res.getState())
export default createStore(reducer)